import {
  type RouteRecordRaw,
  createRouter,
  createWebHashHistory,
} from "vue-router";
import Screen from "@/views/screen/index.vue";
import event, { EventNames } from "@/api/eventEmitter";
import { ElMessageBox } from "element-plus";

const routes: RouteRecordRaw[] = [
  {
    path: "/",
    redirect: "/screen",
  },
  {
    path: "/screen",
    component: Screen,
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

event.on(EventNames.API_INVALID, () => {
  ElMessageBox.alert("接口响应错误！", "提示");
});

event.on(EventNames.API_SESSION_EXPIRED, () => {
  ElMessageBox.alert("登录过期！", "提示");
});

export default router;
